// import store from '@/store';
// import axios from 'axios'
import request from './request.js'

//1.设置axios默认基本路径前缀
// axios.defaults.baseURL = process.env.VUE_APP_AJAX_URL;//VUE_APP_AJAX_URL为程序不同环境配置的基本路径

/**
 * @desc 描述用户登录
 * @param { username:String,password:String } user 
 * @returns 登录消息
 * @author ljy
 * @date 2022年7月14日11:09:21
 */
//2.为登录验证发送axios请求，封装成方法方便页面分别调用
//axios中，get的第二个参数是config(配置)，post请求第二个参数是data，
const userLogin = function (user = {}) {//登录接口
    return request.post("/login", user, {
        isPublic: true // 自定义配置 = 表示该请求不需要授权)
        // .then((response)=>{
        //     return response.data
        // })
    })
}

//左侧的菜单栏接口数据
const getLeftMenu = function () {
    return request.get("/menus", {
        // headers:{
        //     Authorization:store.state.token
        // }
    })
}
//查询用户列表数据
const getUserList = function (params = {}) {
    return request.get("/users", {
        params
    })
}

//添加用户
const addUserList = function (user) {
    return request.post("/users", user, {

    })
}

//通过用户id修改用户状态
const updateUserSateById = function (id, state) {
    return request.put(`/users/${id}/state/${state}`, {
    })
}

//根据id编辑用户信息
const updateUserList = function (id = "", data = {}) {
    return request.put(`/users/${id}`, data)
}

//删除用户列表数据
const removeUserList = function (id = "") {
    return request.delete(`/users/${id}`)
}

//分配用户角色
const allotUserRole = function (id, params) {
    return request.put(`users/${id}/role`, params, {
    })
}

//查询角色列表数据
const getRolesList = function () {
    return request.get("/roles", {})
}

//添加角色列表数据
const addRoleList = function (role) {
    return request.post("/roles", role, {
    })
}


//编辑角色
const updateRoleList = function (id, role) {
    return request.put(`/roles/${id}`, role, {
    })
}
//删除角色
const removeRoleList = function (id) {
    return request.delete(`/roles/${id}`, {
    })
}
//查询权限列表
const getRightsList = function (type = "list") {
    return request.get(`/rights/${type}`, {})
}
//更新roles权限
const updateRightsList = function (roleId, rids) {
    return request.post(`roles/${roleId}/rights`, rids)
}
//查询商品列表数据
const getGoodsList = function (params = {}) {
    return request.get("/goods", {
        params
    })
}
//删除商品
const deleteGoodsList = function (id) {
    return request.delete(`goods/${id}`, {})
}
//查询商品分类数据
const getSortsList = function (params = {}) {
    return request.get("/categories", {
        params
    })
}
//添加商品分类数据categories
const addSortsList = function (params) {
    return request.post("/categories", params, {})
}

//编辑商品分类数据categories
const updateSortsList = function (id, params) {
    return request.put(`/categories/${id}`, params, {})
}
//删除商品分类数据categories
const deleteSortsList = function (id) {
    return request.delete(`/categories/${id}`, {
    })
}

//通过id查询商品列表数据
const getGoodsListById = function (gid) {
    return request.get(`/goods/${gid}`, {
    })
}

//通过id查询参数数据
const getParameListById = function (pid, params = {}) {
    return request.get(`/categories/${pid}/attributes`, {
        params
    })
}

//通过id添加动态参数或静态属性
const addParameListById = function (pid, params) {
    return request.post(`categories/${pid}/attributes`, params)
}

//通过id和attrId更改动态参数或静态属性
const updateParameListByIdAndAttrId = function (pid, attrId, params) {
    return request.put(`categories/${pid}/attributes/${attrId}`, params)
}
//通过id和attrId删除动态参数或静态属性
const deleteParameListByIdAndAttrId = function (pid, attrId) {
    return request.delete(`categories/${pid}/attributes/${attrId}`)
}

//查询订单数据
const getOrdersList = function (params = {}) {
    return request.get("/orders", {
        params
    })
}
//查询订单详情
const getOrderDetailById = function (id) {
    return request.get(`orders/${id}`, {}
    )
}
//同步商品属性
const getGoodsDetailByattributes = function (id) {
    return request.put(`goods/${id}/attributes`, {}
    )
}
//修改收货地址
const updateOrderAddressById = function (id) {
    return request.put(`orders/${id}/address`, {}
    )
}
//查看物流信息
const getLogisticsData = function (id) {
    return request.get(`/kuaidi/${id}`, {}
    )
}

//3.为了方便所有方法全局调用，将方法以对象的方式放在api中，
const api = {
    userLogin, getLeftMenu, getUserList, updateUserSateById, updateUserList,
    removeUserList, allotUserRole, getRolesList, addUserList, addRoleList, updateRoleList,
    removeRoleList, getRightsList, getGoodsList, deleteGoodsList, getSortsList, addSortsList, updateSortsList,
    deleteSortsList, getGoodsListById, getParameListById, getOrdersList, addParameListById,
    updateParameListByIdAndAttrId, deleteParameListByIdAndAttrId, updateRightsList,
    getOrderDetailById,getGoodsDetailByattributes,updateOrderAddressById,getLogisticsData
}

//4.将所有的方法导出在根目录方便全局调用
export default {
    ...api,
    install(Vue) {
        Vue.prototype.$api = api
    }
}